package Year22_Month04.day08;

import java.util.Arrays;

public class 移除元素 {
    public static int removeElement(int[] nums, int val) {
        int size = nums.length;
        int index = 0;
        for (int i = 0; i < nums.length; i++) {
            if(nums[i] != val){
                nums[index] = nums[i];
                index++;
                size--;
            }else{
                size--;
            }
        }
        System.out.println(Arrays.toString(nums));
        System.out.println();
        return size;
    }

    public static void main(String[] args) {
        int[] arr = {0,1,2,2,3,0,4,2};

        System.out.println(removeElement(arr,2));
        System.out.println();
    }
}
